//
//  HNSH_CartShopBottomView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/2.
//

#import "HNSH_CartShopBottomView.h"

@interface HNSH_CartShopBottomView ()

/* moneyLabel */
@property (nonatomic, strong) UILabel *moneyLabel;
/* payButton */
@property (nonatomic, strong) UIButton *payButton;
@end

@implementation HNSH_CartShopBottomView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self configUI];
    }
    return self;
}

- (void)setMoneyString:(NSString *)moneyString {
    self.moneyLabel.text = [NSString stringWithFormat:@"合计：¥%@",moneyString];
    self.moneyLabel.attributedText = [ST_AttributeLabelTool handleLabelWithContent:self.moneyLabel.text SelectContent:@"合计：" CommonFont:self.moneyLabel.font SpeFont:[UIFont systemFontOfSize:12] Color:[UIColor appGrayLabelColor]];
}

- (void)setIsEdit:(BOOL)isEdit {
    _isEdit = isEdit;
    self.moneyLabel.hidden = isEdit;
    [self.payButton setTitle:isEdit ? @"删除" :@"结算" forState:UIControlStateNormal];
    self.payButton.backgroundColor = isEdit ? [UIColor appRedLabelColor] : [UIColor appGreenColor];
}

- (void)configUI {
    [self addSubview:self.selectButton];
    [self addSubview:self.payButton];
    [self addSubview:self.moneyLabel];
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-138);
        make.centerY.equalTo(self.mas_centerY);
        make.height.mas_equalTo(30);
    }];
    self.moneyLabel.attributedText = [ST_AttributeLabelTool handleLabelWithContent:self.moneyLabel.text  SelectContent:@"合计：" CommonFont:self.moneyLabel.font SpeFont:[UIFont systemFontOfSize:12] Color:[UIColor appBlackLabelColor]];
}

#pragma mark lazy
- (UIButton *)selectButton {
    if (!_selectButton) {
        _selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _selectButton.frame = CGRectMake(0, 0, 100, 50);
        [_selectButton setImage:[UIImage imageNamed:@"base_select_off"] forState:UIControlStateNormal];
        [_selectButton setImage:[UIImage imageNamed:@"base_select_on"] forState:UIControlStateSelected];
        [_selectButton setTitle:@"全选" forState:UIControlStateNormal];
        [_selectButton setTitleColor:[UIColor appBlackLabelColor] forState:UIControlStateNormal];
        _selectButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [_selectButton HNSH_layoutButtonWithEdgeInsetsStyle:HHZXButtonStyleTextRight imageTitleSpace:8];
    }
    return _selectButton;
}

- (UILabel *)moneyLabel {
    if (!_moneyLabel) {
        _moneyLabel = [[UILabel alloc]init];
        _moneyLabel.text = @"合计：¥0.00";
        _moneyLabel.textColor = [UIColor appGreenColor];
        _moneyLabel.font = [UIFont boldSystemFontOfSize:14];
    }
    return _moneyLabel;
}

- (UIButton *)payButton {
    if (!_payButton) {
        _payButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _payButton.frame = CGRectMake(kScreenWidth-127, 7, 107, 36);
        [_payButton setTitle:@"结算" forState:UIControlStateNormal];
        [_payButton setTitleColor:[UIColor appWhiteLabelColor] forState:UIControlStateNormal];
        _payButton.titleLabel.font = [UIFont systemFontOfSize:14];
        _payButton.backgroundColor = [UIColor appGreenColor];
        _payButton.layer.cornerRadius = 8.0f;
        _payButton.layer.masksToBounds = YES;
        WeakSelf(weakSelf);
        [[_payButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            if (weakSelf.payBlock) {
                weakSelf.payBlock();
            }
        }];
    }
    return _payButton;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
